﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Reflection; 

namespace MyWebsite 
{ 
/// <summary> 
/// Stops the ASP.NET AppDomain being restarted (which clears 
/// Session state, Cache etc.) whenever a folder is deleted. 
/// </summary> 
public class StopAppDomainRestartOnFolderDeleteModule : IHttpModule 
{ 
public void Init(HttpApplication context) 
{ 
PropertyInfo p = typeof(HttpRuntime).GetProperty("FileChangesMonitor", 
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); 
object o = p.GetValue(null, null); 
FieldInfo f = o.GetType().GetField("_dirMonSubdirs", 
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase); 
object monitor = f.GetValue(o); 
MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", 
BindingFlags.Instance | BindingFlags.NonPublic); 
m.Invoke(monitor, new object[] { }); 
} 
public void Dispose() { } 
} 
} 


